layui.use(['table', 'admin', 'ax'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var dataApi = "/orderInfo";


    /**
     * 参数配置管理 table表id(每次需要修改表格ID)
     */
    var SysConfig = {
        tableId: "orderInfoTable"
    };


    /**
     * 初始化表格的列
     */
    SysConfig.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'orderNo', sort: true, align: "center", title: '订单编号'},
            {field: 'money', sort: true, align: "center", title: '金额'},
            {field: 'status', sort: true, align: "center", title: '状态'},
            {field: 'moneybackType', sort: true, align: "center", title: '回款类型'},
            {field: 'createTime', sort: true, align: "center", title: '创建时间'},
            {field: 'realName', sort: true, align: "center", title: '所属用户'},
            {field: 'phone', sort: true, align: "center", title: '所属用户电话'},
            {field: 'proxyName', sort: true, align: "center", title: '所属代理'}
        ]];
    };

    /**
     * 点击查询按钮
     */
    SysConfig.search = function () {
        var queryData = {};//查询参数的封装对象
        queryData['infoUserId'] = $("#infoUserId").val();
        queryData['orderNo'] = $("#orderNo").val();
        queryData['status'] = $("#status").val();
        queryData['startTime'] = $("#startTime").val();
        queryData['endTime'] = $("#endTime").val();

        table.reload(SysConfig.tableId, {
            where: queryData, page: {curr: 1}
        });//使用查询条件刷新表格并显示列表第一页数据
    };


    /**
     * 导出excel按钮
     */
    SysConfig.exportExcel = function () {
        var checkRows = table.checkStatus(SysConfig.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 渲染表格 填充数据
    var tableResult = table.render({
        elem: '#' + SysConfig.tableId,
        url: Feng.ctxPath + dataApi + '/selectMyOrderInfo',
        page: true,
        height: "full-158",
        cellMinWidth: 120,
        cols: SysConfig.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        SysConfig.search();
    });

    // 导出excel
    $('#btnExp').click(function () {
        SysConfig.exportExcel();
    });

});
